package com.lg.partition13;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/27 22:40
 */
public class P1216数字三角形 {

    private static final int N = 1010;
    private static int[][] g = new int[N][N], f = new int[N][N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 1; i <= n; i++) {
            String[] ss = reader.readLine().split(" ");
            for (int j = 1; j <= i; j++) {
                g[i][j] = Integer.parseInt(ss[j - 1]);
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                f[i][j] = Math.max(f[i - 1][j], f[i - 1][j - 1]) + g[i][j];
                ans = Math.max(ans, f[i][j]);
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
